﻿using System;

namespace _06_Ex03
{
    class Program
    {
        static int SumVals(params int[] vals)
        {
            int sum = 0;
            foreach (int val in vals)
            {
                sum += val;
            }
            return sum;
        }
        static void ShowDouble(ref int val)
        {
            val *= 2;
        }
        static int MaxValue(out int maxIndex, params int[] vals)
        {
            int maxVal = vals[0];
            maxIndex = 0;
            for (int i = 1; i < vals.Length; i++)
            {
                if (vals[i] > maxVal)
                {
                    maxVal = vals[i];
                    maxIndex = i;
                }
            }
            return maxVal;
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            int sum = SumVals(1, 5, 58, 28, 456, 5, 2);
            Console.WriteLine($"Summed Values = {sum}");

            Console.WriteLine($"sum is {sum}");
            ShowDouble(ref sum);
            Console.WriteLine($"sum is {sum}");

            int[] array = { 65, 4, 98, 63, 98, 2, 986, 127 };
            int maxIndex;

            Console.WriteLine($"The maximum value in array is " +
                $"{MaxValue(out maxIndex, array)}");
            Console.WriteLine($"The first occurrence of this value is at element " +
                $"{maxIndex + 1}");

            Console.ReadKey();
        }
    }
}
